﻿/// <reference path="../../Scripts/commen_js/MJ_JSComment.js" />
function no_button() {
    $("#LoginBox_two").fadeOut("fast");
    $("#LoginBox_two").css({ display: 'none' });
}
function yes_button() {
    var type = aftersale.handletype;
    var sql = "";
    var id = aftersale.handleid;
    if (type == 1) {
        var ids = id.replace("xiugai", "");
        var dd = $("#" + ids + "select").find("option:selected").text();
        dd = dd == "未处理" ? "3" : dd == "已处理" ? "4" : "";
        if (dd == "") {
            return;
        }
        sql = "update Orders_Record set finished='" + dd + "' where id='" + ids + "' ";
    }
    else if (type == 0) {
        var ids = id.replace("delete", "");
        sql = "update Orders_Record set deletes='0' where id='" + ids + "' ";
    }
    else { return;}
    poststr = "{\"type\":\"handleaftersale\",\"htmldata\":\"" + sql + "\"}";
    aftersale.postajaxs(poststr, aftersale.showdata);
}
var aftersale = {
    getdata: function (indexpage, indexwhere) {
        poststr = "{\"type\":\"aftersale\",\"pagecurrent\":\"" + indexpage + "\",\"indexwhere\":\"" + indexwhere + "\"}";
        this.postajaxs(poststr, this.showdata);
    },
    postajaxs: function (postdata, fangfa) {
        mj_ajax("../Handler1.ashx", "json", postdata, fangfa)
    },
    xuhao :1,
    change_color: 1,
    handleid: 1,
    handletype:1,//1是修改0是删除
    changege_input : 1,
    showdata: function (data) {
        $("#LoginBox_two").fadeOut("fast");
        $("#LoginBox_two").css({ display: 'none' });
    if (data.result == "ok")  {
        var record_count1 = data.record_count;
        record_count = record_count1 == 0 ? 1 : record_count1;
        var page_curent = data.page_curent;
        var datatable = data.table;
       
        var str = "";
        var table = document.getElementById("tbodyList");
        $("#tbodyList").empty();
        if (datatable.length != 0) {
            for (var i = 0; i < datatable.length; i++) {
                var tr = document.createElement("tr");
                if (aftersale.change_color % 2 == 0) {
                    tr.className = "bg-info";
                    aftersale.change_color++;
                }
                else {
                    aftersale.change_color++;
                }
                var td1 = document.createElement("td");
                td1.innerHTML = datatable[i].product_name;
                var td2 = document.createElement("td");
                td2.innerHTML = datatable[i].price;
                var td3 = document.createElement("td");
                td3.innerHTML = datatable[i].product_type;
                var td4 = document.createElement("td");
                td4.innerHTML = datatable[i].phone;
                var td5 = document.createElement("td");
                td5.innerHTML = datatable[i].building + "-" + datatable[i].dorm;
                var td6 = document.createElement("td");
                td6.innerHTML = datatable[i].productset;


                var td10 = document.createElement("td");
                td10.innerHTML = datatable[i].leave_word;


                var td7 = document.createElement("td");
                td7.innerHTML = datatable[i].createtime.replace("T", " ");


                //下拉框
                var td8 = document.createElement("td");
                var select = document.createElement("select");
                select.id = datatable[i].id + "select";
                select.className = "select_";
                var option = document.createElement("option");
                option.setAttribute("value", "yisong");
                option.innerHTML = "未处理";
                var option1 = document.createElement("option");
                option1.setAttribute("value", "weisong");
                option1.innerHTML = "已处理";
                //0是已送1是未送2是在送
                var statee = $.trim(datatable[i].finished);
                if (statee == "4") {
                    option1.setAttribute("selected", "selected");
                }
                else  {
                    option.setAttribute("selected", "selected");
                }
                select.appendChild(option);
                select.appendChild(option1);
                td8.appendChild(select);
                //下拉框结束
                var td9 = document.createElement("td");
                td9.id = "small"
                var label1 = document.createElement("input");
                label1.id ="xiugai"+ datatable[i].id;
                label1.value = "修改";
                label1.setAttribute("type", "button");
                label1.className = "btn btn-info input1";
                label1.onclick = function () {
                    aftersale.xiugai(this.id);
                }
                var label2 = document.createElement("input");
                label2.id = "delete"+datatable[i].id;
                label2.value = "删除";
                label2.setAttribute("type", "button");
                label2.className = "btn btn-default input2";
                label2.onclick = function () {
                    aftersale.delect(this.id);
                }
                td9.appendChild(label1);
                td9.appendChild(label2);
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                tr.appendChild(td10);
                tr.appendChild(td7);
                tr.appendChild(td8);
                tr.appendChild(td9);
                table.appendChild(tr);
            }
        }
        else {
            $("#tbodyList").empty();
        }
        //下面进行的是分页
        $("#record_shu").text(" 总记录数" + record_count1);
        if (record_count % 10 != 0) {
            page_shu = record_count / 10 + 1;
            page_shu = parseInt(page_shu)
        }
        else {
            page_shu = record_count / 10;
        }
        var options = {
            totalPages: page_shu,
            numberOfPages: 5,
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "第一页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "最后一页";
                    case "page":
                        return page;
                }
            },
            onPageClicked: function (event, originalEvent, type, page) {
                var state = $.trim($("#dateboxs").text());
                state = state == "全部" ? "" : state == "已处理" ? "4" : state == "未处理" ? "3" : "";
                var keyword = $.trim($("#keyword").val());
                aftersale.getdata(page, state + "|" + keyword);
            }
        }
        $('#example').bootstrapPaginator(options);
   
    }

    else {
        layer.alert(data.msg, {
            icon: 1,
            skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
        })
    }

    },
    search: function () {
        var state = $.trim($("#dateboxs").text());
        state = state == "全部" ? "" : state == "已处理" ? "4" : state == "未处理" ? "3" : "";
        var keyword = $.trim($("#keyword").val());
        aftersale.getdata("1", state + "|" + keyword);
    },
    xiugai: function (id) {
        aftersale.handleid = id;
        aftersale.handletype = 1;
        $("#content_two").text("确定保存修改？");
        $("#LoginBox_two").fadeIn("fast");
        $("#LoginBox_two").css({ display: 'block' });

    },
    delect: function (id) {
        aftersale.handleid = id;
        aftersale.handletype = 0;
        $("#content_two").text("确定删除这条记录？");
        $("#LoginBox_two").fadeIn("fast");
        $("#LoginBox_two").css({ display: 'block' });
    },
};

